#include<iostream>
#include<cstdio>
using namespace std;
int main()
{
	int ans, n;
	while (cin >> n) {
		ans = (((n * (n + 1) / 2) % 10000) * ((n * (n + 1) / 2) % 10000)) % 10000;
		printf("%04d\n", ans);
	}
	return 0;
}